<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!doctype html>
<html lang="en">
<head>
  	<meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>注册</title>
    <link rel="stylesheet" href="${ctxPath }/static/customer/css/reg.css">
    <script src="${ctxPath }/static/customer/js/jquery-1.8.3.min.js"></script>
    <script src="${ctxPath }/static/customer/layer/mobile/layer.js"></script>
</head>
<body>

  <div class="container">
        <div class="content">
            <form class="regForm">
                <!--电话-->
                <div class="row">
                   <label for="phone" class="regLable" name="phone">电<span style="color:#f3f3f3;">话</span>话：</label>
                    <input type="text" name="phone" class="inpVal telVal" placeholder="请输入手机号"><span readonlyunselectable="on" readonly class="sendNumBtn" >获取验证码</span>
                </div>
                <!--验证码-->
                <div class="row">
                    <label for="code" class="regLable" name="code">验证码：</label>
                    <input type="text" name="code" class="inpVal codeVal">
                </div>
                <div class="row">
                    <input type="button" class="regBtn" value="确    定">
                </div>
            </form>
        </div>
    </div>
    <script>
    var countdown=60;
    function settime(obj) {
        if (countdown == 0) {
            obj.removeAttribute("disabled");
            obj.innerHTML="获取验证码";
            countdown = 60;
            return;
        } else {
            obj.setAttribute("disabled", true);
            obj.innerHTML=countdown +"s";
            countdown--;
        }
        setTimeout(function() {
                settime(obj) }
            ,1000)
    }
    $(".telVal").blur(function(){
    	$.post(
   			"${ctxPath }/customer/isRegisted",
   			{phone:$(".telVal").val()},
   			function(data){
    			var data2 = JSON.parse(data);
    			if(data2.status == 1 ){
    				//alert("222");
    				layer.open({
    	                content: data2.message
    	                ,skin: 'msg'
    	                ,time: 2 //2秒后自动关闭
    	            });
    			}else{
    				$(".sendNumBtn").click(function(){
    		            if($(".telVal").val() !== ""){
    		                var re = /^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/;
    		                var tel = $(".telVal").val();   
    		                var retu=re.test(tel);
    		                if(!retu){
    		                    layer.open({
    		                        content: '请输入正确格式的手机号'
    		                        ,skin: 'msg'
    		                        ,time: 2 //2秒后自动关闭
    		                    });
    		                    $(".telVal").val("");
    		                    return false;
    		                }else{
    		                	//lkb0.lukebang.com.cn
    		                    $.post("${ctxPath }/upload/sendMaByPhone",{sendType:4,phone:tel},function(data){
    		                        //console.log(data);
    		                        /*if(data.status==0){
    		                            alert("验证码已发送您的手机，请注意查收！");
    		                            $(".regLable").attr("number",data.data);
    		                        }*/
    		                    },"json")
    		                    settime(this);
    		                    return true;
    		                }
    		            }else{
    		                layer.open({
    		                    content: '请输入手机号'
    		                    ,skin: 'msg'
    		                    ,time: 2 //2秒后自动关闭
    		                });
    		                //alert("请输入手机号");
    		            }
    		        })
    			}
    		})
	})
        

    /*点击注册验证手机号*/

    //var reg = /(1[3-9]\d{9}$)/;
    //var re=new RegExp(/^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/);
	
	
    $(".regBtn").click(function(){
        if($(".telVal").val() == ""){
            layer.open({
                content: '请输入手机号'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
            return false;
        }else if($(".codeVal").val() == ""){
            layer.open({
                content: '请输入验证码'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
        } else{
        	var tel = $(".telVal").val();
            var re = /^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/;
            var retu=re.test(tel);
            if(!retu){
                //alert("请输入正确格式的手机号");
                layer.open({
                    content: '请输入正确格式的手机号'
                    ,skin: 'msg'
                    ,time: 2 //2秒后自动关闭
                });
                return false;
            }else{
            	var a=	"${identity }";
            	var customerId="${customerId }";
            	var url="";
            	if(a=='0'){
            		url='${ctxPath }/customer/customerRefer';
            	}else{
            		url='${ctxPath }/customer/subordinate';
            	}
            	if(!url){
            		return;
            	}
                var codeNum = $(".codeVal").val();
                var hideNum = $(".customerId").val();
                $.post(url,{customerId:customerId,phone:tel,vertifyCode:codeNum},function(data){
                	var data = JSON.parse(data);
                	console.log(typeof (data.status) );
                    if(data.status == 0){
                        layer.open({
                            content: data.message
                            ,skin: 'msg'
                            ,time:5//2秒后自动关闭
                        });
                        if(a=='0'){
                        	location.href='http://fir.im/lukejiaju';
                        }
                    }else{
                    	layer.open({
                            content: data.message
                            ,skin: 'msg'
                            ,time:5//2秒后自动关闭
                        });
                    }
                })
                $(this).attr("disabled","true");
                //console.log($(".regLable").attr("number"));
                //lalert("222");
                setTimeout('$(".regBtn").removeAttr("disabled")',3000);
                return true;
            }

        }
    })
    </script>
</body>
</html>